[codex] Allow public search suggestions#1388
Conversation
🦋 Changeset detectedLatest commit: 49fd03d The changes in this PR will be included in the next version bump. This PR includes changesets to release 14 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
/review |
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/auth-atproto
@emdash-cms/blocks
@emdash-cms/cloudflare
@emdash-cms/contentful-to-portable-text
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/plugin-cli
@emdash-cms/plugin-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/sandbox-workerd
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-field-kit
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
There was a problem hiding this comment.
This is a clean, minimal bug fix that correctly allows anonymous GET access to /_emdash/api/search/suggest by adding it to PUBLIC_API_EXACT, mirroring the existing public /_emdash/api/search route. The approach is sound: the endpoint is read-only, the underlying query already hardcodes status = 'published' and respects soft-deletion, and management endpoints (/rebuild, /enable, /stats) remain protected by auth middleware and the existing token-scope rules.
I verified:
- Auth middleware:
isPublicEmDashRouteuses exact matching, so sibling management routes are not accidentally exposed. - Scope enforcement: Token-authenticated GET requests to
search/suggeststill requirecontent:readscope via the existing prefix rule; anonymous requests bypass scope checks as intended. - CSRF: GET/HEAD on public routes skip CSRF, which is safe since the route only exports a GET handler.
- SQL: The suggestion query uses Kysely parameterized values and
validateIdentifierfor collection slugs; no injection risk. - Tests: The unit tests in
oauth-csrf.test.tscorrectly verify anonymous access and continued privacy ofsearch/rebuild. The integration test adds a proper draft-exclusion regression test. The test-helper fix to omit body on GET/HEAD is a nice cleanup. - Changeset: Accurate patch-level changeset for the
emdashpackage.
I found no logic bugs, regressions, or AGENTS.md convention violations. Good to go.
What does this PR do?
Allows anonymous GET requests to
/_emdash/api/search/suggestso the built-inLiveSearchautocomplete mode works on public sites.The route is added as an exact public API match alongside
/_emdash/api/search; search management endpoints such as/_emdash/api/search/rebuildremain authenticated. The suggestion query still only returns published content, with a regression test covering draft exclusion.Closes #
Type of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runmessages.pochanges except in translation PRs — a workflow extracts catalogs on merge tomain.AI-generated code disclosure
Screenshots / test output
pnpm --silent lint:json | jq '.diagnostics | length'->0pnpm --silent lint:quickpnpm --dir packages/core exec vitest run tests/unit/middleware/oauth-csrf.test.ts tests/integration/search/suggest.test.ts-> 20 tests passedpnpm --dir packages/core typecheckpnpm --filter emdash buildpnpm lintpnpm typecheckpnpm formatgit diff --check